using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWASFARB
    {
        public DataRow Convert2WASFARB(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWASFARB(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WASFMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WASFKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WASFWERK"] = " ".PadRight(3 ); 
         dwReturn["WASFABT"] = " ".PadRight(3 ); 
         dwReturn["WASFART"] = " ".PadRight(20 ); 
         dwReturn["WASFVAR"] = " ".PadRight(2 ); 
         dwReturn["WASFZUART"] = " ".PadRight(1 ); 
         dwReturn["WASFSPRKZ"] = " ".PadRight(1 ); 
         dwReturn["WASFZUSATZ"] = " ".PadRight(10 ); 
         dwReturn["WASFCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["WASFBEZ"] = " ".PadRight(20 ); 
         dwReturn["WASFAENDZL"] = " ".PadRight(0 ); 
         dwReturn["WASFAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["WASFAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["WASFNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["WASFNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWASFARB(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWASFARB(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWASFARB(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWASFARB(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWASFARB(dwLocal, ITXDBVERSION);
            }
            UpdateWASFARB(dwLocal);
        }
        public void InsertWASFARB(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WASFARB(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWASFARB(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WASFARB WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WASFARB  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WASFARB";
            Return = Result;
            return Return;
        }
        public void DeleteWASFARB(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WASFARB   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWASFARB(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WASFARB SET "
                    +"WASFMANDANT= :WASFMANDANT,"
                    +"WASFKUNDNR= :WASFKUNDNR,"
                    +"WASFWERK= :WASFWERK,"
                    +"WASFABT= :WASFABT,"
                    +"WASFART= :WASFART,"
                    +"WASFVAR= :WASFVAR,"
                    +"WASFZUART= :WASFZUART,"
                    +"WASFSPRKZ= :WASFSPRKZ,"
                    +"WASFZUSATZ= :WASFZUSATZ,"
                    +"WASFCOLORIT= :WASFCOLORIT,"
                    +"WASFBEZ= :WASFBEZ,"
                    +"WASFAENDZL= :WASFAENDZL,"
                    +"WASFAENDBEN= :WASFAENDBEN,"
                    +"WASFAENDDAT= :WASFAENDDAT,"
                    +"WASFNEUBEN= :WASFNEUBEN,"
                    +"WASFNEUDAT= :WASFNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WASFMANDANT", OracleType.NVarChar).Value = dwData["WASFMANDANT"].ToString(); 
          or1.Parameters.Add("WASFKUNDNR", OracleType.NVarChar).Value = dwData["WASFKUNDNR"].ToString(); 
          or1.Parameters.Add("WASFWERK", OracleType.NVarChar).Value = dwData["WASFWERK"].ToString(); 
          or1.Parameters.Add("WASFABT", OracleType.NVarChar).Value = dwData["WASFABT"].ToString(); 
          or1.Parameters.Add("WASFART", OracleType.NVarChar).Value = dwData["WASFART"].ToString(); 
          or1.Parameters.Add("WASFVAR", OracleType.NVarChar).Value = dwData["WASFVAR"].ToString(); 
          or1.Parameters.Add("WASFZUART", OracleType.NVarChar).Value = dwData["WASFZUART"].ToString(); 
          or1.Parameters.Add("WASFSPRKZ", OracleType.NVarChar).Value = dwData["WASFSPRKZ"].ToString(); 
          or1.Parameters.Add("WASFZUSATZ", OracleType.NVarChar).Value = dwData["WASFZUSATZ"].ToString(); 
          or1.Parameters.Add("WASFCOLORIT", OracleType.NVarChar).Value = dwData["WASFCOLORIT"].ToString(); 
          or1.Parameters.Add("WASFBEZ", OracleType.NVarChar).Value = dwData["WASFBEZ"].ToString(); 
          or1.Parameters.Add("WASFAENDZL", OracleType.NVarChar).Value = dwData["WASFAENDZL"].ToString(); 
          or1.Parameters.Add("WASFAENDBEN", OracleType.NVarChar).Value = dwData["WASFAENDBEN"].ToString(); 
          or1.Parameters.Add("WASFAENDDAT", OracleType.NVarChar).Value = dwData["WASFAENDDAT"].ToString(); 
          or1.Parameters.Add("WASFNEUBEN", OracleType.NVarChar).Value = dwData["WASFNEUBEN"].ToString(); 
          or1.Parameters.Add("WASFNEUDAT", OracleType.NVarChar).Value = dwData["WASFNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
